require(['init'], function () {

  function getStudentId(cb) {
    ajaxMethod({
      url: '/api/user/current',
      success: function (data, status) {
        if(status.code == 0) {
          ajaxMethod({
            url: '/api/student/user/' + data.userid,
            success: function (data, status) {
              if(status.code == 0) {
                cb && cb(data.studentuid)
              }
            }
          })
        }
      }
    })
  }

  function getFeedbackList(id) {
    ajaxMethod({
      url: '/api/comment/student/'+id,
      success: function (data, status) {
        if(status.code == 0) {
          var $feedbackList = $('#J_feedbacklist').html('')
          var $thead = $('<thead>\
            <tr>\
             <th>'+i18next.t('table.no')+'</th>\
             <th>'+i18next.t('table.coursename')+'</th>\
             <th>'+i18next.t('table.lessonsname')+'</th>\
             <th>'+i18next.t('table.schooltime')+'</th>\
             <th>'+i18next.t('table.starrating')+'</th>\
             <th>'+i18next.t('table.rewardnumber')+'</th>\
             <th>'+i18next.t('table.teacherevaluation')+'</th>\
            </tr>\
          </thead>').appendTo($feedbackList)



          if(!data.length) {
            $feedbackList.parent().append('<div style="margin-top:50px;text-align:center">'+i18next.t('input.nullresults')+'</div>')
            return
          }

          var $tbody = $('<tbody></tbody>').appendTo($feedbackList)
          $.each(data, function (i, item) {
            var $tr = $('<tr></tr>')
            $tr.append('<td>'+(i+1)+'</td>')
            $tr.append('<td>'+ (item.course||'') +'</td>')
            $tr.append('<td>'+ item.schedule +'</td>')
            $tr.append('<td>'+ item.begintime +'</td>')
            $tr.append('<td>'+ (item.star_level+''+i18next.t('table.star')+'') +'</td>')
            $tr.append('<td>'+ item.class_status +'</td>')
            $tr.append('<td>'+ item.comment +'</td>')

            $tbody.append($tr)
          })
        }
      }
    })
  }

  getStudentId(getFeedbackList)
})
